# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import pymongo


class JijinPipeline(object):
    def __init__(self):
        myclient = pymongo.MongoClient('127.0.0.1', 27017)
        mydb = myclient['深圳交易所']
        if '基金列表' in mydb.list_collection_names():
            mydb.drop_collection('基金列表')
        self.mycol = mydb['基金列表']
        self._id = 1

    def process_item(self, item, spider):
        item['_id'] = self._id
        self.mycol.insert_one(dict(item))
        self._id += 1
        return item
